#include <bits/stdc++.h>
using namespace std;

/**
 * 时间复杂度：O(mn)
 * 空间复杂度：O(1)
 * 
 * 旋转矩阵
 */
int a[1000][1000], b[1000][1000];
int main() {
    int n, m, r;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            b[i][j] = a[n - j - 1][i];
            cout << b[i][j] << " ";
        }
        cout << endl;
    }
}